<div class="span12">
    <div class="box gradient">
        <div class="title" style="text-align: center">
            <h4>
                Facture
            </h4>
        </div>
        <div class="content noPad clearfix">
            <table style="width: 100%">
                <tbody>
                    <tr>
                        <td style="width: 25%">
                            <label>Date:</label>
                            <span> {{facture.date|date('d/m/Y')}}</span>
                        </td>
                        <td style="width: 25%">
                            <label>Heure:</label>
                            <span> {{facture.getTime}}</span>
                        </td>
                        <td style="width: 25%">
                            <label>Client:</label>
                            <span>{{facture.bonLivraisons[0].client}}</span>
                        </td>
                        <td style="width: 25%">
                            <label>Reference:</label>
                            <span>{{facture.reference}}</span>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div> 
    </div>
</div>
{% set total_ttc_facture = 0 %}
{% for a,lignes in alllignes %}
{% set taxes = alltaxes[a] %}
<div class="span12"  style="margin-left:0" >
    <div class="box">
        <div class="title" style="text-align: center" onclick="minimize({{a}})">
            <h4>
                    {{facture.bonLivraisons[a].reference}}
            </h4>
        </div>
            <div style="display: block;" class="content noPad" id="div_{{a}}">
                <table class="responsive table table-bordered">
                    <thead>
                        <tr>
                            <th style="width:3%">N°</th>
                            <th style="width:15%">Reference</th>
                            <th style="width:30%">Designation</th>
                            <th style="width:7%">Qte</th>
                            <th style="width:10%">P.U.HT</th>
                            <th style="width:5%">TVA</th>
                            <th style="width:5%">Remise</th>
                            <th style="width:10%">P.U.TTC</th>
                            <th>Total</th>
                        </tr>
                    </thead>
                    <tbody>
                {% set total_ttc = 0 %}
                {% for i,ligne in lignes %}
                            <tr>
                                <td>{{i+1}}</td>
                                <td>{{ligne.article.reference}}</td>
                                <td>{{ligne.article.designation}}</td>
                                <td>{{ligne.quantite|number_format(2)}}</td>
                                <td>{{ligne.prixUnitaireHt}}</td>
                                <td>{{ligne.tauxTva|number_format(2)}}%</td>
                                <td>{{ligne.tauxRemise|number_format(2)}}</td>
                        {% set ttc = ligne.prixUnitaireHt*(1+ligne.tauxTva/100)*(1-ligne.tauxRemise/100) %}
                                <td>{{ttc|number_format(3)}}</td>
                        {% set total = ttc*ligne.quantite %}
                        {% set total_ttc = total+total_ttc %}
                                <td>{{total|number_format(3)}}</td>
                            </tr>
                {% endfor %}
                 {% set total_ttc_facture = total_ttc_facture+total_ttc %}
                        </tbody>
                    </table>
                </div>
            </div>
            <table style="width: 100%" id="table_{{a}}">
                <tr style="width: 100%">
                    <td style="width: 20%">
                        <div class="span2">
                            <div class="box gradient">
                                <div class="content noPad clearfix">
                                    <table class="responsive display table table-bordered" width="100%" cellspacing="0" cellpadding="0" border="0">
                                        <thead>
                                            <tr>
                                                <th>Taxe</th>
                                                <th>Base</th>
                                                <th>Montant</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                    {% set totaux = 0 %}
                    {% for taxe in taxes %}
                                                <tr>
                                                    <td>{{taxe.tva|number_format(2)}}%</td>
                                                    <td>{{taxe.base|number_format(3)}}</td>
                            {% set totaux = totaux + taxe.montant %}
                                                    <td>{{taxe.montant|number_format(3)}}</td>
                                                </tr>
                    {% endfor %}
                                                <tr>
                                                    <td>Totaux</td>
                                                    <td></td>
                                                    <td>{{totaux|number_format(3)}}</td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </td>
                        <td style="width: 70%"></td>
                        <td>
                            <div class="span2" style="width: 100%">
                                <div class="content noPad clearfix">
                                    <table class="responsive display table table-bordered" width="100%" cellspacing="0" cellpadding="0" border="1px" style="border:#D0E9F5 ">
                                        <thead>
                                            <tr>
                                                <th class="center" style="text-align: center">TOTAL TTC</th>
                                                <th id="total_ttc" class="center">{{total_ttc|number_format(3)}}</th>
                                            </tr>
                                        </thead> 
                                    </table>
                                </div>
                            </div>
                        </td>
                    </tr>    
                </table>


            </div>
{% endfor %}
            <table style="width: 100%">
                <tr style="width: 100%">
                    <td style="width: 20%">
                        <div class="span2">
                            <div class="box gradient">
                                <div class="content noPad clearfix">
                                    <table class="responsive display table table-bordered" width="100%" cellspacing="0" cellpadding="0" border="0">
                                        <thead>
                                            <tr>
                                                <th>Taxe</th>
                                                <th>Base</th>
                                                <th>Montant</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                    {% set totaux = 0 %}
                    {% for taxe in taxefacture %}
                                                <tr>
                                                    <td>{{taxe.tva|number_format(2)}}%</td>
                                                    <td>{{taxe.base|number_format(3)}}</td>
                            {% set totaux = totaux + taxe.montant %}
                                                    <td>{{taxe.montant|number_format(3)}}</td>
                                                </tr>
                    {% endfor %}
                                                <tr>
                                                    <td>Totaux</td>
                                                    <td></td>
                                                    <td>{{totaux|number_format(3)}}</td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </td>
                        <td style="width: 30%"></td>
                        <td>
                            <div class="span2">
                                <table class="responsive display table table-bordered" cellspacing="0" cellpadding="0" border="0">
                                    <tbody>
                                        <tr>
                                            <td style="text-align: center;width: 40%">TOTAL</td>
                                            <td style="text-align: center;width: 60%">{{total_ttc_facture|number_format(3)}}</td>
                                        </tr>
                                        <tr>
                                            <td style="text-align: center">Timbre</td>
                                            <td style="text-align: center">{{timbre|number_format(3)}}</td>
                                        </tr>
                                        <tr>
                                            <th style="text-align: center">Total TTc</th>
                                            {% set ttc = timbre + total_ttc_facture %}
                                            <th style="text-align: center">{{ttc|number_format(3)}}</th>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </td>
                    </tr>
                </table>


                <div class="span2" style="margin-right: 0">
                    <table>
                        <tr>
                            <td><input style="width:100px" type="button" class="btn btn-info cut-icon-previous"  value="Retour" onclick="retourListeDevis()"></td>
                        </tr>
                        <tr>
                            <td style="height: 20px"></td>
                        </tr>
                        <tr>
                            <td><input style="width: 100px" type="button" class="btn btn-info cut-icon-previous"  value="Imprimer" onclick=""></td>
                        </tr>
                    </table>
                </div>

                <script>
                    $(document).ready(function() {
                        var len = {{alllignes|length}}
                        for (i = 0; i < len; i++) {
                            minimize(i)
                        }
                    })
                    function retourListeDevis() {
                        $.ajax({
                            url: "{{ path('gds_vente_liste_facture') }}",
                            data: 'retour=true' + '&numero=' + lf[0] + '&raison_social=' + lf[1] + '&date1=' + lf[2] + '&date2=' + lf[3] + '&heure1=' + lf[4] + '&heure2=' + lf[5]
                                    + '&reference=' + lf[6] + '&designation=' + lf[7] + '&ttc1=' + lf[8] + '&ttc2=' + lf[9] + '&is_cloture=' + lf[10],
                            success: function(data) {
                                $('#div_liste_facture').replaceWith(data)
                                $('#filtre_numero').val(lf[0])
                                $('#filtre_raison_social').val(lf[1])
                                $('#filtre_date1').val(lf[2])
                                $('#filtre_date2').val(lf[3])
                                $('#filtre_reference').val(lf[6])
                                $('#filtre_designation').val(lf[7])
                                $('#filtre_ttc1').val(lf[8])
                                $('#filtre_ttc2').val(lf[9])
                            }
                        })
                    }
                    function minimize(i) {
                        if ($('#table_' + i).is(":visible")) {
                            $('#table_' + i).hide()
                            $('#div_' + i).hide()
                        } else {
                            $('#table_' + i).show()
                            $('#div_' + i).show()
                        }
                    }
                    </script>